function wangyan(e) {
  axios({
    url: '/score/list',
    method: 'get',

  }).then(({
    data: res
  }) => {
    if (res.code == 0) {
      let arr = []

      for (let k in res.data) {
        arr.push(`<tr>
        <th scope="row">${k}</th>
        <td>${res.data[k].name}</td>
        <td data-id=${k} data-batch="1" class="score">${res.data[k].score[0]}</td>
        <td data-id=${k} data-batch="2" class="score">${res.data[k].score[1]}</td>
        <td data-id=${k} data-batch="3" class="score">${res.data[k].score[2]}</td>
        <td data-id=${k} data-batch="4" class="score">${res.data[k].score[3]}</td>
        <td data-id=${k} data-batch="5" class="score">${res.data[k].score[4]}</td>
      </tr>`)
      }
      document.querySelector('tbody').innerHTML = arr.join('')

    }
  });
}
wangyan()
document.querySelector('tbody').onclick = function (e) {
  if (e.target.className == 'score') {
    let input = document.createElement('input')
    let num = e.target.innerHTML
    input.value = e.target.innerHTML
    e.target.innerHTML = ''
    e.target.appendChild(input)
    input.focus()
    input.onkeyup = function (e) {
      if (e.keyCode != 13) {
        return
      }
      axios({
        url: '/score/entry',
        method: 'POST',
        data: {
          // this代表input，但是属性绑定到他的父盒子td上了
          "stu_id": this.parentNode.getAttribute('data-id'), // 学生id
          // batch是第几次考试
          "batch": this.parentNode.getAttribute('data-batch'),
          "score": this.value // 学生成绩
        }
      }).then(({
        data: res
      }) => {
        if (res.code == 0) {
          toastr.success(res.message)
          wangyan()
        }
      });
    }
    input.onblur = function () {
      e.target.innerHTML = num
    }
  }
}